package com.bank.manage.controller;

import com.bank.manage.model.BankAccessType;
import com.bank.manage.model.BankAccessWalletRecord;
import com.bank.manage.model.dto.RecordsDto;
import com.bank.manage.model.param.BankQueryParam;
import com.bank.manage.model.vo.RecordsVo;
import com.bank.manage.model.vo.RequestVo;
import com.bank.manage.service.BankAccessTypeService;
import com.bank.manage.service.BankAccessWalletRecordService;
import com.bank.manage.service.Impl.RecordsServiceImpl;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.gavin.core.annotation.LogRecord;
import org.gavin.core.annotation.Safety;
import org.gavin.core.domain.R;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * RecordsController
 *
 * @author grl
 * @date 2024/4/1
 */
@Validated
@RestController
@RequiredArgsConstructor
public class RecordsController {

    private final BankAccessWalletRecordService bankAccessWalletRecordService;
    private final RecordsServiceImpl recordsService;
    private final BankAccessTypeService accessTypeService;

    /**
     * 获取记录请求
     *
     * @return
     */
    @Safety
    @LogRecord(description = "获取记录请求")
    @PostMapping(value = "/record/request")
    public R<RequestVo> getRequestVo(@RequestBody @Valid BankAccessWalletRecord record) {
        return R.ok(bankAccessWalletRecordService.getRequestVo(record));
    }

    /**
     * 操作记录
     *
     * @return
     */
    @Safety
    @LogRecord(description = "操作记录")
    @PostMapping(value = "/record/save")
    public R<Boolean> addRecord(@RequestBody @Valid RecordsDto dto) {
        return R.ok(recordsService.addRecord(dto));
    }

    /**
     * 获取访问类型
     *
     * @return
     */
    @Safety
    @LogRecord(description = "获取访问类型")
    @GetMapping(value = "/record/access/type")
    public R<List<BankAccessType>> getAccessType() {
        return R.ok(accessTypeService.list());
    }

    /**
     * 增加操作记录
     *
     * @return
     */
    @Safety
    @LogRecord(description = "查询操作记录")
    @PostMapping(value = "/record/query")
    public R<RecordsVo> recordQuery(@RequestBody @Valid BankQueryParam param) {

        return R.ok(recordsService.recordQuery(param));
    }
}
